using System;
using System.Collections.Generic;

namespace PowerSearch.AppServices.Parser
{
	public class FeedParserManager
	{
		private static Dictionary<string, IFeedParser> _parsers;
		private static FeedParserFactory _factory;

		public FeedParserManager() : this(null)
		{
		}

		public FeedParserManager(FeedParserFactory factory)
		{
			_parsers = new Dictionary<string, IFeedParser>();
			_factory = factory ?? new FeedParserFactory();
		}

		public IFeedParser GetParser(string provider)
		{
			IFeedParser parser;
			_parsers.TryGetValue(provider, out parser);

			if (parser == null)
			{
				parser = _factory.GetParser(provider);
				if (parser != null)
					_parsers.Add(provider, parser);
			}

			return parser;
		}
	}
}

